import { Tabs, WhiteSpace } from 'antd-mobile';
import React, { Component } from 'react';
import './commodity.css';
import CommoditySearch from './CommoditySearch';
import GotoPage from './GotoPage';
import { withRouter } from "react-router-dom";
import { ExamineCreator, GoodsSuccess, GoodsFail } from '../Redux/ActionCreator';
import { connect } from 'react-redux';
import { Send_tim } from '../IM/actiontim';
//商品审核右半部分页面
class Commodity extends Component {
    constructor(props) {
        super(props);
        this.state = {
        };
        this.props.dispatch(ExamineCreator())
    }
    render() {
        return (
            <div className="body_right">
                <div className='right_top'>
                    <p>待审核商品</p>
                </div>
                <div className='right_middle'>
                    <div className='search_id'>
                        <p>输入查找的内容</p>
                        <CommoditySearch />
                        <div className='examinetable'>
                            <table border='0' cellpadding='5' cellspacing='0' className='mytable'>
                                <thead>
                                    <tr>
                                        <th>编号</th>
                                        <th>ID</th>
                                        <th>所属商家ID</th>
                                        <th>标题</th>
                                        <th>描述</th>
                                        <th>价格</th>
                                        <th>地址</th>
                                        <th>发布时间</th>
                                        <th>营业时间</th>
                                        <th>图片</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {
                                        this.props.examinereducer.map((item, index) => {
                                            return (
                                                <tr>
                                                    <td>{index + 1}</td>
                                                    <td>{item.commodity_temp_id}</td>
                                                    <td>{item.business_id}</td>
                                                    <td>{item.commodity_temp_title}</td>
                                                    <td>{item.commodity_temp_describe}</td>
                                                    <td>{item.commodity_temp_money}</td>
                                                    <td>{item.commodity_temp_addres}</td>
                                                    <td>{item.commodity_temp_time}</td>
                                                    <td>{item.commodity_temp_t}</td>
                                                    <td id='examine_pic'><img key={index} src={`http://www.h5weixin.club:1025/api/image/${item.commodity_temp_pic}`} /></td>
                                                    <td>
                                                        <button className='solute'
                                                        onClick={() => {
                                                            // const adminpwd = prompt('请输入管理员登录密码：')
                                                            // if (adminpwd) {
                                                            this.props.dispatch(GoodsSuccess(item.commodity_temp_id))
                                                            let res = this.props.fruiterreducer.filter((item2)=>{
                                                                return item2.business_id == item.business_id 
                                                            })
                                                            console.log(res)
                                                            Send_tim(res[0].business_phone,`您发布的商品《${item.commodity_temp_title}》审核通过`)
                                                            // }
                                                            return false;
                                                        }}>通过</button>
                                                        <button className='delete'
                                                            onClick={() => {
                                                                const adminpwd = prompt('请输入管理员登录密码：')
                                                                if (adminpwd) {
                                                                    this.props.dispatch(GoodsFail(item.commodity_temp_id, adminpwd))
                                                                }
                                                                return false;
                                                            }}
                                                        >删除</button></td>
                                                </tr>
                                            )
                                        })
                                    }
                                </tbody>
                            </table>
                        </div>
                        {/* 分页 */}
                        <GotoPage />
                    </div>
                </div>
            </div>
        );
    }
}
const mapStateToProps = (state) => ({
    examinereducer: state.examinereducer,
    fruiterreducer:state.fruiterreducer
})
export default connect(mapStateToProps)(withRouter(Commodity));
